package org.hamster.toolkit.mainview
{
	import mx.collections.ArrayCollection;
	
	import spark.components.Window;
	
	import org.hamster.common.puremvc.mediator.BaseMediator;
	import org.hamster.toolkit.mainview.events.IndexViewEvent;
	import org.hamster.toolkit.mainview.vo.IndexCategoryItemVO;
	import org.hamster.toolkit.mainview.vo.IndexCategoryVO;
	import org.hamster.toolkit.module.hash.HashWindow;
	import org.hamster.toolkit.module.http.HttpWindow;
	import org.hamster.toolkit.module.oauth.OauthWindow;
	
	public class IndexViewMediator extends BaseMediator
	{
		public static const NAME:String = "org.hamster.toolkit.mainview.view.IndexViewMediator";
		
		public var categoryList:ArrayCollection = new ArrayCollection();
		
		public function IndexViewMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
		}
		
		override public function onRegister():void
		{
			app.addEventListener(IndexViewEvent.OPEN_ITEM, openItemHandler);
			
			var algorithmCategory:IndexCategoryVO = new IndexCategoryVO();
			algorithmCategory.name = "Algorithm & Hash";
			algorithmCategory.itemList = new ArrayCollection();
			categoryList.addItem(algorithmCategory)
			
			var oauth:IndexCategoryItemVO = new IndexCategoryItemVO();
			oauth.name = "OAuth 2.0 Algorithm";
			oauth.window = OauthWindow;
			algorithmCategory.itemList.addItem(oauth);
			
			var hash:IndexCategoryItemVO = new IndexCategoryItemVO();
			hash.name = "Hash";
			hash.window = HashWindow;
			algorithmCategory.itemList.addItem(hash);
			
			var http:IndexCategoryItemVO = new IndexCategoryItemVO();
			http.name = "Http";
			http.window = HttpWindow;
			algorithmCategory.itemList.addItem(http);
			
			var editorCategory:IndexCategoryVO = new IndexCategoryVO();
			editorCategory.name = "Editors";
			editorCategory.itemList = new ArrayCollection();
			categoryList.addItem(editorCategory)
			
			var i18nEditor:IndexCategoryItemVO = new IndexCategoryItemVO();
			i18nEditor.name = "I18N Editor";
			i18nEditor.window = I18nEditorWindow;
			editorCategory.itemList.addItem(i18nEditor);
			
			app.categoryList = categoryList;
		}
		
		override public function onRemove():void
		{
			
		}
		
		private function openItemHandler(event:IndexViewEvent):void
		{
			var window:Window = new event.indexCategoryItemVO.window();
			window.open();
		}
		
		public function get app():IndexView
		{
			return viewComponent as IndexView;
		}
	}
}